Skip to content

curl

curl 官网 https://curl.se/

shell

http://www.taobao.com/help/getip.php

curl --socks5 125.119.175.48:8909 https://dev.kdlapi.com/testproxy

#带密码的认证
curl --socks5 125.119.175.48:8909 -U user:pwd https://dev.kdlapi.com/testproxy

#字串类型
#-x host:port
#-x [protocol://[user:pwd@]host[:port]
#--proxy [protocol://[user:pwd@]host[:port]
#protocol默认为http_proxy,其他可能的值包括:http_proxy HTTPS_PROXY、socks4、socks4a、socks5;

curl -x "socks5://user:pwd@125.119.175.48:8909" https://dev.kdlapi.com/testproxy

Python测试

python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
使用requests请求代理服务器
请求http和https网页均适用
"""

import requests

# 提取代理API接口,获取1个代理IP
api_url = "https://dps.kdlapi.com/api/getdps/?secret_id=o1fjh1re9o28876h7c08&signature=xxxxx&num=1&pt=2&sep=1"

# 获取API接口返回的代理IP
proxy_ip = requests.get(api_url).text

# 用户名密码认证(私密代理/独享代理)
username = "username"
password = "password"
proxies = {
    "http": "socks5h://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip},
    "https": "socks5h://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip}
}

# 白名单方式(需提前设置白名单)
# proxies = {
#     "http": "socks5h://%(proxy)s/" % {"proxy": proxy_ip},
#     "https": "socks5h://%(proxy)s/" % {"proxy": proxy_ip}
# }

# 要访问的目标网页
target_url = "https://dev.kdlapi.com/testproxy"

# 使用代理IP发送请求
response = requests.get(target_url, proxies=proxies)

# 获取页面内容
if response.status_code == 200:
    print(response.text)